$(function () {
	

	//经销商ID  globalDealerId
	//门店ID  globalStoreId
		var scollHeight = document.documentElement.scrollHeight;
	    $(".layui-fluid").height(scollHeight-100);
	    $(".layui-fluid").css("min-height","680px");
		
		var clueData = [];
		var globalDate = new Array(7);
		var clueBaseListsCount = new Array(7);
		var orderListsCount = new Array(7);
		var totalDataY = ['线索池','成交量总计','采购车辆总计'];
		var totalDataValue = [];
		var totalDataColor=["#fc9b32","#f9719f","#4386fb"]
		var totalData = [];
		//日期转换
		function getNowFormatDate(day) {
		    var curDate = new Date();
		    var date = new Date(curDate.getTime() + day*24*60*60*1000);
		    var seperator1 = "/";
		    var year = date.getFullYear();
		    var month = date.getMonth() + 1;
		    var strDate = date.getDate();
		    if (month >= 1 && month <= 9) {
		        month = "0" + month;
		    }
		    if (strDate >= 0 && strDate <= 9) {
		        strDate = "0" + strDate;
		    }
		    var currentdate = month + seperator1 + strDate;
		    return currentdate;
		}
		var currentDate = getNowFormatDate(0)
		var preDateOne = getNowFormatDate(-1)
		var preDateTwo = getNowFormatDate(-2)
		var preDateThree = getNowFormatDate(-3)
		var preDateFour = getNowFormatDate(-4)
		var preDateFive = getNowFormatDate(-5)
		var preDateSix = getNowFormatDate(-6)
		globalDate = [preDateSix,preDateFive,preDateFour,preDateThree,preDateTwo,preDateOne,currentDate];
	     $.ajax({
	         type: "POST",
	         url: hostUrl+"/indexData/dealerList",
	         data:{dealerId:globalDealerId,storeId:globalStoreId},
	         async: false,
	         success:function(res){
	        	 var res = JSON.parse(res)
	        	 if(res&&res.status==1){
	        		var clueBaseLists = res.clueBaseList;
	        		var orderLists = res.orderList
	        		clueData.push(res.clueBaseCount);
	        		clueData.push(res.stock60Count);
	        		clueData.push(res.stockCount);
	        		clueData.push(res.orderCount);
	        		totalDataValue.push(res.clueBaseCountAll)
	        		totalDataValue.push(res.orderCountAll)
	        		totalDataValue.push(res.carCountAll)
	        		for(var i=0;i<globalDate.length;i++){
	        			if(clueBaseLists.length>0){
	        				for(var j=0;j<clueBaseLists.length;j++){
	                			if(globalDate[i] == clueBaseLists[j].date){
	                				clueBaseListsCount[i] = clueBaseLists[j].count;
	                			}
	                		}
							if(clueBaseListsCount[i] == undefined){
								clueBaseListsCount[i] = 0
							}
	        			}else{
	        				clueBaseListsCount[i] = 0
	        			}
	        			if(orderLists.length>0){
	        				for(var j=0;j<orderLists.length;j++){
	                			if(globalDate[i] == orderLists[j].date){
	                				orderListsCount[i] = orderLists[j].count;
	                			}
	                		}
							if(orderListsCount[i] == undefined){
								orderListsCount[i] = 0
							}
	        			}else{
	        				orderListsCount[i] = 0
	        			}
	        		}
	        	 }
	         }
	     });
	     for(var i=0;i<totalDataValue.length;i++){
	    	 totalData.push({
	    		 value:totalDataValue[i],
	    		 itemStyle:{
	               normal:{color:totalDataColor[i]}
	           }
	    	 })
	     }
	     $("span.nub").each(function(e){
	 		$(this).text(clueData[e])
	 	})
	    map1();
	    map2();
	    map3();
	    function map1(){
	        var echart = echarts.init(document.getElementById('echart1'));
	        echart.setOption({
	            color:"#fdd6cc",
	            title : {
	                text: '新增线索分析',
	            },
	            tooltip : {
	                trigger: 'axis'
	            },
	            xAxis : [
	                {
	                    type : 'category',
	                    boundaryGap : false,
	                    data : globalDate
	                }
	            ],
	            yAxis : [
	                {
	                    type : 'value'
	                }
	            ],
	            series : [
	                {
	                    name:'新增线索',
	                    type:'line',
	                    smooth:true,
	                    itemStyle: {normal: {areaStyle: {type: 'default'}}},
	                    data:clueBaseListsCount
	                }
	            ]
	        })
	        window.addEventListener("resize", function () {
	            echart.resize();
	        });
	    }
	    function map2(){
	        var echart = echarts.init(document.getElementById('echart2'));
	        echart.setOption({
	            color:"#99e8fa",
	            title : {
	                text: '成交量分析',
	            },
	            tooltip : {
	                trigger: 'axis'
	            },
	            xAxis : [
	                {
	                    type : 'category',
	                    boundaryGap : false,
	                    data : globalDate
	                }
	            ],
	            yAxis : [
	                {
	                    type : 'value'
	                }
	            ],
	            series : [
	                {
	                    name:'成交量',
	                    type:'line',
	                    smooth:true,
	                    itemStyle: {normal: {areaStyle: {type: 'default'}}},
	                    data:orderListsCount
	                }
	            ],
	            grid:{
	                left:'18%',
	                bottom:80
	            }
	        })
	        window.addEventListener("resize", function () {
	            echart.resize();
	        });
	    }
	     function map3(){
	        var echart = echarts.init(document.getElementById('echart3'));
	        echart.setOption(option = {
	            tooltip : {
	                trigger: 'axis'
	            },
	            xAxis : [
	                {
	                    type : 'value',
	                    axisLabel : {
	                        formatter: '{value}'
	                    }
	                }
	            ],
	            yAxis : [
	                {
	                    type : 'category',
	                    data : totalDataY
	                }
	            ],
	            series : [
	                {
	                    type:'bar',
	                    data:totalData,
	                    barWidth:30
	                }
	            ]
	        })
	        window.addEventListener("resize", function () {
	            echart.resize();
	        });
	    }

	
})

